//公用方法
    //Date Wed Mar 17 2021 13:52:00 GMT+0800 (中国标准时间) 转标准的日期格式
    export function dateFormat(date){
        let y = date.getFullYear()
        let m = date.getMonth() + 1
        m = m < 10 ? ('0' + m) : m
        let d = date.getDate()
        d = d < 10 ? ('0' + d) : d
        let h =date.getHours()
        h = h < 10 ? ('0' + h) : h
        let M =date.getMinutes()
        M = M < 10 ? ('0' + M) : M
        let s =date.getSeconds()
        s = s < 10 ? ('0' + s) : s
        let dateTime= y + '-' + m + '-' + d + ' ' + h + ':' + M + ':' + s;
        return dateTime
    }
    //获取可视区的宽高
    export function getViewPortOffset() {
        if (window.innerWidth) {
            return {
                w: window.innerWidth,
                h: window.innerHeight
            }
        } else if (document.compatMode = "BackCompat") {
            return {
                w: document.body.clientWidth,
                h: document.body.clientHeigth
            }
        } else {
            return {
                w: document.documentElement.clientWidth,
                h: document.documentElement.clientHeight
            }
        }
    }
     //完成将 toChineseNum， 可以将数字转换成中文大写的表示，处理到万级别，例如 toChineseNum(12345)，返回 一万二千三百四十五。
     export function toChinesNum(num) {
        let changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']; //changeNum[0] = "零"
        let unit = ["", "十", "百", "千", "万"];
        num = parseInt(num);
        let getWan = (temp) => {
            let strArr = temp.toString().split("").reverse();
            let newNum = "";
            for (var i = 0; i < strArr.length; i++) {
                newNum = (i == 0 && strArr[i] == 0 ? "" : (i > 0 && strArr[i] == 0 && strArr[i - 1] == 0 ? "" : changeNum[strArr[i]] + (strArr[i] == 0 ? unit[0] : unit[i]))) + newNum;
            }
            return newNum;
        }
        let overWan = Math.floor(num / 10000);
        let noWan = num % 10000;
        if (noWan.toString().length < 4) noWan = "0" + noWan;
        return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
        
    }
    // 简单js随机字符串生成
    export function random(){
        return Math.random().toString(36).substr(2) + Date.now().toString(36);
    }
    // 时间戳转年月日 this.formatTime(time,'Y-M-D h:m:s')
    export function formatTime(number,format) {  
        var formateArr  = ['Y','M','D','h','m','s'];  
        var arrList   = [];  
        var date = new Date(number);  
        arrList.push(date.getFullYear());  
        arrList.push(this.formatNumber(date.getMonth() + 1));  
        arrList.push(this.formatNumber(date.getDate()));  
        arrList.push(this.formatNumber(date.getHours()));  
        arrList.push(this.formatNumber(date.getMinutes()));  
        arrList.push(this.formatNumber(date.getSeconds()));  
        for (var i in arrList)  
        {  
          format = format.replace(formateArr[i], arrList[i]);  
        }  
        return format;  
    }
    //补0 用于时间戳补0
    function formatNumber(n) {
        n = n.toString()  
        return n[1] ? n : '0' + n  
    }
    //数字前面补0
    export function PrefixZero(num) {
        if (num < 10) {
            return "0" + num;
        } else if (num < 100) {
            return "" + num;
        } else if (num < 1000) {
            return "" + num;
        } else {
            return num;
        }
    }
    // 格式化金钱 数字转成带逗号的金钱字符串保留两位小数
    export function toMoney(val) { //val 数字number
        var str = (val / 100 * 100).toFixed(2) + ''
        var intSum = str.substring(0, str.indexOf(".")).replace(/\B(?=(?:\d{3})+$)/g, ',') //取到整数部分
        var dot = str.substring(str.length, str.indexOf(".")) //取到小数部分搜索
        var ret = intSum + dot
        return ret
    }
    //获取页面参数 获取url中的参数
    export function getPageParam() {
        let url = window.location.href
        let urlStr = url.split("?")[1] //？后面的部分
        let option = {}
        if (urlStr) {
            let keyValArr = urlStr.split("&")
            keyValArr.forEach(function (str, index) {
                let arr = str.split("=")
                let key = arr[0]
                let val = arr[1]
                option[key] = val
            })
        }
        return option
    }
